﻿<!DOCTYPE html>
<html lang="en">
	<head>
		<title>Molgav email</title>
		<meta charset="utf-8">
		<script src="localstore.js"></script>
		<style>
			html, body {
				font-family: 'Gidugu', serif;
				background-color:#000;
				color: #fff;	
				font-size: xx-large;
				text-align: center;
			}
			a {
				color: #99f;
				text-decoration: none;
			}
			h1 {
				text-align: center;
				border-bottom: 1px solid #333;
			}
			.ftr {
				text-align: left;
				border-top: 1px solid #333;
			}
			.cntr {
				text-align: left;
				display: inline-block;
			}
			@font-face {
			  font-family: 'Gidugu';
			  font-style: normal;
			  font-weight: 400;
			  src: local('Gidugu'), url(gidugu.woff2) format('woff2');
			  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
			}
		</style>
	</head>
	<body>
		<h1>Share via email</h1>
		<div class='cntr'>
			<ul>
				<li><a id='sharemail' href="#">Create message </a>in email client</li>
				<li><a id='copylink' href="javascript:copyLink();">Copy</a> <span id=short><i>downloading...</i></span> into clipboard</li>
			</ul>
		</div>
		<p class="ftr">Return to <a href="index.html">editor</a></p>
		<script>
			var encoded = encodeState();
			var url="http://tinyurl.com/api-create.php?url=2165136";
			var xmlHttpRequest = new XMLHttpRequest();
			
			console.log(xmlHttpRequest);
			xmlHttpRequest.onreadystatechange = function () {
				console.log( xmlHttpRequest.responseText);
			}
			xmlHttpRequest.open("GET", url, true);
			xmlHttpRequest.setRequestHeader("Authorization", "nope"); 
			xmlHttpRequest.send();
			//var sharemail = document.getElementById('sharemail');
			//sharemail.href = "mailto:to@any.body?subject=RiffShare&body=look to https://surikov.github.io/RiffShareAndroid/app/src/main/assets/load.html?riff=" + encoded;
			
			clipboardDiv = document.createElement('div');
			clipboardDiv.style.fontSize = '12pt'; // Prevent zooming on iOS
			// Reset box model
			clipboardDiv.style.border = '0';
			clipboardDiv.style.padding = '0';
			clipboardDiv.style.margin = '0';
			// Move element out of screen
			clipboardDiv.style.position = 'fixed';
			clipboardDiv.style['right'] = '-9999px';
			clipboardDiv.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
			// more hiding
			clipboardDiv.setAttribute('readonly', '');
			clipboardDiv.style.opacity = 0;
			clipboardDiv.style.pointerEvents = 'none';
			clipboardDiv.style.zIndex = -1;
			clipboardDiv.setAttribute('tabindex', '0'); // so it can be focused
			clipboardDiv.innerHTML = '';
			document.body.appendChild(clipboardDiv);
			function copyLink() {
				copyHtmlToClipboard("https://surikov.github.io/RiffShareAndroid/app/src/main/assets/load.html?riff=" + encoded);
			}
			function copyHtmlToClipboard(html) {
				clipboardDiv.innerHTML = html;
				var focused = document.activeElement;
				clipboardDiv.focus();
				window.getSelection().removeAllRanges();
				var range = document.createRange();
				range.setStartBefore(clipboardDiv.firstChild);
				range.setEndAfter(clipboardDiv.lastChild);
				window.getSelection().addRange(range);
				var ok = false;
				try {
					if (document.execCommand('copy')) {
						ok = true;
					} else {
						alert('Can not copy');
					}
				} catch (err) {
					alert('Error ' + err);
				}
				focused.focus();
			}
			
		</script>
	</body>
</html>
